<template>
	<view class="content">
		<view class="item" @click="jumpPage(0)">
			<image src="/static/icon/bank.png" mode="" class="iscc"></image>
			<view class="">
				<view>银行卡</view>
				<view class="hui">开户银行-{{financeInfo.yh_khh}}</view>
				<view class="hui">支行名称-{{financeInfo.yh_zhmc}}</view>
				<view class="hui">开户名-{{financeInfo.yh_kh}}</view>
				<view class="hui">卡号-{{financeInfo.yh_id}}</view>
			</view>
		</view>
		
		<view class="item" @click="jumpPage(1)">
			<image src="/static/icon/bichang.jpg" mode=""  class="iscc"></image>
			<view>
				<view>钱包-{{financeInfo.qb_name}}</view>
				<view class="hui">地址-{{financeInfo.qb_address}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:null,
				financeInfo:{
					yh_khh:null,
					yh_zhmc:null,
					yh_kh:null,
					yh_id:null,
					qb_name:null,
					qb_address:null
				},
				user_token:null
			};
		},
		onLoad() {
			this.getUserInfo()
			this.getFinance()
		},
		methods:{
			getUserInfo(){
				let that = this
				if(that.userInfo == null){
					uni.getStorage({
						key: 'user_token',
						success: function (res) {
							that.user_token = res.data
							that.checkUser()
						},
						fail: function(res){
							uni.showToast({
								title:'请先登录',
								icon:'none',
								success() {
									uni.redirectTo({
										url:'/pages/login/login',
									})
								}
							})
							
						}
					});
				}
			},
			checkUser(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getUserInfo',
					method:'POST',
					header: {token:that.user_token},
					success(res) {
						if(res.data.code == 401){
							uni.removeStorage({
								key:'user_token',
								success() {
									uni.showToast({
										icon:'none',
										title:'登录已失效,请重新登录',
										success() {
											setTimeout(function(){
												uni.redirectTo({
													url:'/pages/login/login'
												})
											})
										}
									})
								}
							})
						}
						that.userInfo = res.data.data
					},
					fail() {
						uni.showToast({
							title:'网络错误',
							icon:'none',
						})
					}
				})
			},
			getFinance(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getFinance',
					header:{token:that.user_token},
					method:'POST',
					success(res) {
						if(res.data.code == 1){
							that.financeInfo = res.data.data
						}
					}
				})
			},
			jumpPage(data){
				if(data == 1){
					uni.navigateTo({
						url:'/pages/token/token'
					})
				}else{
					uni.navigateTo({
						url:'/pages/bank/bank'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f4f4f4;
	}
	.content{
		display: flex;
		flex-direction: column;
		
	}
	.item{
		display: flex;
		align-items: center;
		margin: .8rem .8rem 0 .8rem;
		background: #fff;
		padding: 1rem;
		border-radius: 15px;
	}
	.iscc{
		width: 2rem;
		height: 2rem;
		margin-right: 1rem;
	}
	.hui{
		color: #666;
		font-size: 11px;
	}
</style>
